/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Comparator;
import java.util.stream.Stream;

/**
 * <p>Project: javase - Stream5
 * <p>Powered by webrx On 2021-12-22 17:54:11
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Stream7 {
    public static void main(String[] args) {
        var ss = Stream.of(
                new Student(1, "lisi1", 22, "男"),
                new Student(2, "lisi2", 22, "女"),
                new Student(3, "lisi3", 18, "男"),
                new Student(4, "lisi4", 18, "女"),
                new Student(5, "lisi5", 28, "女"),
                new Student(5, "lisi6", 28, "男"),
                new Student(6, "james", 58, "aa"));

        //allMatch() 所有元素都符合条件，返回true,只要有一个元素不符合就返回false
        //var f = ss.allMatch(o -> o.getAge() >= 18);
        //System.out.println(f);

        //anyMathch() 只要有一个元素符合条件，返回true，如何全部都不符合，就返回false
        //var f = ss.anyMatch(o -> o.getName().startsWith("张"));
        //System.out.println(f);

        //noneMatch() 所有元素都不符合条件，返回true,否则返回false
        //var f = ss.noneMatch(o -> o.getName().length() > 4);
        //System.out.println(f);

        //var o = ss.skip(1).findFirst().get();
        //System.out.println(o);

        //
        //var o = ss.findAny().get();
        //System.out.println(o);

        //System.out.println(ss.count()); 返回元素个数，
        //年龄最大student
        //System.out.println(ss.max(Comparator.comparingInt(Student::getAge)).get());
        //年龄最大student
        System.out.println(ss.min((a, b) -> b.getAge() - a.getAge()).get());
    }
}
